﻿package UIComponents// ActionScript file
{
	import Classes.GameUtils.LoadImg;
	import Classes.staticinfo.Language;
	
	import MyComponent.MyButton;
	
	import fl.events.ComponentEvent;
	
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.text.TextField;

	public class FrameFriend extends Sprite
	{
		private var lv:TextField;
		private var userName:TextField;
		private var picIcon:IconContainer;
		public var hireBtn:MyButton;
		public var visibleBtn:MyButton;
		public var dingWeiBtn:MyButton;
		public var _bmb:DisplayObject;
		private var _hzSp:IconContainer;
		private var _jobSp:IconContainer;
		private var _nhzSp:IconContainer;
		
		private var _isVisitle:Boolean=false;
		public  var mouseOverFilters:Array=null;
		public  var visitleFilters:Array=null;
		
		public var htx_icon:Sprite;
		
		public function FrameFriend():void
		{
			init();
		}
		
		
		private function init():void
		{
			this.lv=(this.getChildByName("LvSp") as DisplayObjectContainer).getChildByName("txt_lv") as TextField;
			this.userName=this.getChildByName("nameTxt") as TextField;
			this.picIcon=this.getChildByName("container_myImg") as IconContainer;
			this.hireBtn=this.getChildByName("_hireBtn") as MyButton;
			this.visibleBtn=this.getChildByName("_visableBtn") as MyButton;
			this._bmb=this.getChildByName("zhezhao");
			this.dingWeiBtn=this.getChildByName("_dingweiBtn") as MyButton;
			this.hireBtn.visible=this.visibleBtn.visible=this.dingWeiBtn.visible=false;
			this._hzSp=this.getChildByName("hzsp") as IconContainer;
			this._nhzSp=this.getChildByName("nhzSp") as IconContainer;
			this._hzSp.buttonMode=this._nhzSp.buttonMode=true;
			this._jobSp=this.getChildByName("jobSp") as IconContainer;
			this.htx_icon	=	this.getChildByName("htx_icon") as Sprite;
			this.htx_icon.mouseChildren		=	this.htx_icon.mouseEnabled	=	this.htx_icon.visible	=	false;
//			this.visibleHit.visible	=	false;
			
			addLister();
		}
		
		private function addLister():void
		{
			this.addEventListener(MouseEvent.ROLL_OVER,rollOver);
			this.addEventListener(MouseEvent.ROLL_OUT,rollOut);
			this.hireBtn.addEventListener(ComponentEvent.BUTTON_DOWN,hireFriend);
			this.visibleBtn.addEventListener(ComponentEvent.BUTTON_DOWN,visiableFirend);
			this.dingWeiBtn.addEventListener(ComponentEvent.BUTTON_DOWN,selectFun);
			this._hzSp.addEventListener(MouseEvent.CLICK,kanTeQuan);
			this._nhzSp.addEventListener(MouseEvent.CLICK,kanTeQuan);
		}
		
		private function kanTeQuan(e:MouseEvent):void
		{
			if(FlatInfo.isOpenHz)
			{
				friend.kanQQTeQuan();
			}
		}
		
		/**
		 * 雇佣好友 
		 * @param e
		 */		
		private function hireFriend(e:ComponentEvent):void
		{
			friend.hireFriendFun();
		}
		
		/**
		 * 拜访好友 
		 * @param e
		 */		
		private function visiableFirend(e:ComponentEvent):void
		{
			friend.visiableFriendFun();
		}
		
		/**
		 * 在家定位选中改玩家 
		 * @param e
		 */		
		private function selectFun(e:ComponentEvent):void
		{
			this.friend.goMyHome();
		}
		
		private var friend:IFriendInfo;
		public function setFriendData(ifriend:IFriendInfo):void
		{
			var dis:DisplayObject;
			reset();
			this.friend=ifriend;
			if(this.friend.isHired==1)
			{
				this.hireBtn.enabled=false;
			}
			this.lv.text=String(friend.friendLV);
			this.userName.text=null==friend.friendName?"":friend.friendName;
//			trace("this.userName.text="+this.userName.text+"friend.friendName="+friend.friendName);
			var picUrl:String=null==friend.friendViewImg?"":friend.friendViewImg;
			if(picUrl!="")
			{
//				LoadImg.instance.loadingImg(picUrl,setUserPic);
				new LoadImg().loadingImg(picUrl,setUserPic);
			}
			if(this.friend.friendQqVip==0)
			{
				this._hzSp.visible=false;
				this._nhzSp.visible=false;
			}
			else if(this.friend.friendQqVip>0 && this.friend.friendQqVip<9)
			{
				this._hzSp.visible=true;
				this._nhzSp.visible=false;
				dis=this.friend.qqVipIcon;
				dis.width	=	16.75;
				dis.height	=	13.65;
				this._hzSp.addPic(dis,Language.hztq);
			}else
			{
				this._hzSp.visible=false;
				this._nhzSp.visible=true;
				dis=this.friend.qqVipIcon;
				dis.width	=	34.45;
				dis.height	=	15.8;
				this._nhzSp.addPic(dis,Language.hztq);
			}
			if(!FlatInfo.isOPenQQVip)
			{
				this._hzSp.visible=false;
				this._nhzSp.visible=false;
			}
			var tmpJobIcon:DisplayObject=friend.friendJobIcon;
			if(tmpJobIcon)
			{
				tmpJobIcon.width=25;
				tmpJobIcon.height=25;
			}
			this._jobSp.addPic(tmpJobIcon);
			
			this._bmb.visible=false;
		}
		
		private function setUserPic(value:DisplayObject):void
		{
			value.width=48;
			value.height=50;
			this.picIcon.addPic(null);
			this.picIcon.addPic(value);
		}
		
		public function reset():void
		{
			this.friend=null;
			this.lv.text="0";
			this.userName.text="";
			this.picIcon.addPic(null);
			this._bmb.visible=true;
			this.hireBtn.enabled=true;
			this.dingWeiBtn.visible=false;
		}
		
		private function rollOver(evt:MouseEvent):void
		{
			if(null==this.friend) return ;
			if(this.friend.isHired==1)
			{
				this.dingWeiBtn.visible=true;
				this.hireBtn.visible=false;
			}else{
				this.hireBtn.visible=true;
				this.hireBtn.enabled=true;
				this.dingWeiBtn.visible=false;
			}
			this.visibleBtn.visible=true;
			if(this.friend.isMySelft)
			{
				this.visibleBtn.visible=false;
				this.hireBtn.visible=false;
				this.dingWeiBtn.visible=true;
			}
			if(this.friend.friendID==FlatInfo.sysFriendId)
			{
				this.dispatchEvent(new PanelEvent(PanelEvent.FRIENDROLLOVER,true));
			}
			
			if(!this._isVisitle)
			this.filters	=	this.mouseOverFilters;
			
		}
		
		private function rollOut(evt:MouseEvent):void
		{
			this.controlBtn(false);
			if(this.friend && this.friend.friendID==FlatInfo.sysFriendId)
			{
				this.dispatchEvent(new PanelEvent(PanelEvent.FRIENDROLLOUT,true));
			}
			if(!this._isVisitle)
			this.filters	=	null;
		}
		
		
		private function controlBtn(arg:Boolean):void
		{
			this.dingWeiBtn.visible=this.hireBtn.visible=this.visibleBtn.visible=arg;
		}
		
		public function set isVisitle(v:Boolean):void
		{
			this._isVisitle		=	v;
			if(v){
				this.filters	=	this.visitleFilters;
				
			}
			else{
				this.filters	=	null;
			}
		}
		
	}
}